<?php
class Gallery_model extends Model{
	function Gallery_model()
	{
		parent::Model();
	}
	//fetch all wall paper categeories
	function getwallpcategeories()
	{  $this->db->order_by('update_date','desc');
		$this->db->where('parentid',0);
		$query=$this->db->get('gallery_categeory');
		return $query;
			
	}
	
	function recentcategeories()
	{
		$id=0;
		$this->db->where('parentid',$id);
		$this->db->limit('4');
		$this->db->order_by('update_date','desc');
		$query=$this->db->get('gallery_categeory');
		//print_r($query->result_array());
		return $query->result_array();
	}
    function getsubcategeories($recentcategeories,$limit)
	{   $subcategeories = array();
		foreach($recentcategeories as $item)
		{
		 $result= $this->subcategeories($item['id'],$limit,$asii="");
		 $subcategeories[] =  $result;
		 }
		 return $subcategeories;
	}
	//getting recent image id per subcategeory
    function getimages($subcategeories)
	{
		$image = array();
       foreach($subcategeories as $item)
		{ 
		  foreach($item as $item1)
	     { 			
		 $result1= $this->getimages1($item1['id'],$limit=0);
         $image[$item1['id']]=$result1[0]['id'];
		 }
	    }
	    return $image; 
    }
    function subcategeories($id,$limit,$ascii)
	{	
		$this->db->where('parentid',$id);
		if($ascii!="")
		$this->db->like('upper(catname)',chr($ascii),'after');
		
		if($limit==0)
		{
	      $limit=4;
		}
		$this->db->limit($limit);
		$this->db->order_by('catname','asc');
		$this->db->order_by('catname','desc');
		$this->db->order_by('update_date','desc');
		$query=$this->db->get('gallery_categeory');
		return $query->result_array();
		
		
	}
	function getallimages($id)
	{
		$this->db->order_by('id','desc');
		$this->db->where('parentid',$id);
		$query=$this->db->get('gallery_images');
		return $query->result_array();
	}
    function getimages1($id)
	{
		$this->db->where('parentid',$id);
		$this->db->select_max('id');	
		$query=$this->db->get('gallery_images');
		return $query->result_array();
	}
    function galleryview($id,$catid)
	{
		
		$this->db->where('parentid',$catid);
		$query = $this->db->get('gallery_images');
		return $query;
		
	}
}
?>